// pages/homework/homeworkDetails/homeworkDetails.js
import https from '../../../utils/request5.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    examId: null,
    title: null,
    gradeid: null,
    courseid: null,
    classId: null,
    info: {},
    studentList: [],
    showType: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      console.log(options,'uuuuuuuuuuuuuuuuuuuuu');
      this.setData({
        examId: options.examId,
        title: options.title,
        gradeid: options.gradeid,
        courseid: options.courseid,
        classId: options.classId
      })
    this.getInfo()
  },
  showInfo() {
    this.setData({
        showType: !this.data.showType
    })
  },
  async getInfo() {
    let obj = {
      classId: null
    }
      let data = {
        url:`/score/overview/${this.data.examId}?classId=${this.data.classId}`,
        method:'get',
        header:{"content-type":"application/json;charset=UTF-8"}
    }
    let ress = await https(data)  // Now this await is valid
    if(ress&&ress.data.code==200){
      if(ress.data.data!=null){
        ress.data.data.avgScore = ress.data.data.avgScore.toFixed(2);
        ress.data.data.excellentPercent = ress.data.data.excellentPercent.toFixed(2);
        ress.data.data.passPercent = ress.data.data.passPercent.toFixed(2);
        this.setData({
            info: ress.data.data
        })
        console.log(this.data.info,'0000000000000000000');
        // let token = JSON.stringify(ress.data.data)
        // wx.setStorageSync('studentToken',token)
      }
    } else {
        wx.showToast({
            title: ress.data.message,
            icon: 'none',
            duration: 2000 //持续的时间
        })
    }

    let that = this
      let datares = {
        url:`/score/score-details/${this.data.examId}?classId=${this.data.classId}`,
        method:'get',
        header:{"content-type":"application/json;charset=UTF-8"}
    }
    let res = await https(datares)  // Now this await is valid
    if(res&&res.data.code==200){
      if(res.data.data!=null){
        res.data.data.map(items => {
            items.studentNo = items.studentNo.substring(4)
            const entries = Object.entries(items.objectiveMap)
            .map(([key, value]) => ({
                key,
                value,
            }))
            items.objectiveMapList = entries
            const entriess = Object.entries(items.subjectiveMap)
            .map(([key, value]) => ({
                key,
                value,
            }))
            items.subjectiveMapList = entriess
            const entriesss = Object.entries(items.objectiveAnswerMap)
            .map(([key, value]) => ({
                key,
                value,
            }))
            items.objectiveAnswerMapList = entriesss
        })
        this.setData({
            studentList: res.data.data
        })
        console.log(this.data.studentList, '--------------------');
        // let token = JSON.stringify(ress.data.data)
        // wx.setStorageSync('studentToken',token)
      }
    } else {
        wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000 //持续的时间
        })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})